package com.zhp.web;

import com.alibaba.fastjson.JSON;
import com.zhp.common.R;
import com.zhp.service.OrderService;
import com.zhp.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author Lone Ranger
 */
@WebServlet("/payOrder")
public class PayOrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String oid = req.getParameter("oid");
        OrderService orderService = new OrderServiceImpl();
        Integer yyztid = 22;
        int result = orderService.updateOrderStatus(Integer.parseInt(oid), yyztid);

        PrintWriter writer = resp.getWriter();
        String s = "";
        if (result == 1) {
            R<String> r = new R<String>();
            r.setCode(200);
            s = JSON.toJSONString(r);
        } else {
            R<String> r = new R<String>();
            r.setCode(500);
            s = JSON.toJSONString(r);
        }
        writer.write(s);
    }
}
